package com.interest.controller.api;

import com.interest.authorization.annotation.Authorization;
import com.interest.base.entity.ModelBean;
import com.interest.base.utils.ResponseUtils;
import com.interest.modules.trending.entity.Trending;
import com.interest.modules.trending.service.GithubTrendingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/api/github/trending")
public class ApiTrendingController {
    @Autowired
    private GithubTrendingService githubTrendingService;

    @RequestMapping("/list")
    @Authorization
    @ResponseBody
    public ModelBean getList() {
        List<Trending> list = githubTrendingService.getList();
        for (Trending trending : list) {
            trending.setHref("https://github.com" + trending.getHref());
        }

        return ResponseUtils.generateSuccess(list);
    }
}
